<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.ORM.entity.headQ.barcodeGentor.*,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>查询条形码</title>
<%@ include file="../../common/Style.jsp"%>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/conf_files/js/BarcodeSearchKeys.js"></script>

<script type="text/javascript"
	src="<%=request.getContextPath()%>/conf_files/js/HtmlTable.js"></script>
<script>
var newsDataGrid = undefined;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	jQuery.excel('InnerTableContent');
	$("#brandName").focus();
	
	var params = $.serializeObject($('#barcodeSearchForm'));
	newsDataGrid = $('#dataGrid').datagrid({
		url : 'productJSONAction.action',
		queryParams: params,
		fit : true,
		border : false,
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		nowrap : false,
		showFooter:true,
		checkbox:true,
		rownumbers:true,
		columns : [ [
			{			
				field : 'checkBarcode',
				title : '货品条形码',
				width : 120,
				checkbox:true,
				align: 'center'
			},{
			field : 'year',
			title : '年份季度',
			width : 80,
			align: 'center',
			formatter: function (value, row, index){
				return row.year + row.quarter;
			}	
		},{
			field : 'brand',
			title : '品牌',
			width : 105,
			align: 'center'
				
		},{
			field : 'brandComment',
			title : '品牌备注',
			width : 110
				
		},{
			field : 'categoryLevel',
			title : '产品线',
			width : 80,
			align: 'center'
				
		},{
			field : 'category',
			title : '货品类',
			width : 120,
			align: 'center'
				
		},{
			field : 'productCode',
			title : '货号',
			width : 110,
			align: 'center'
				
		},{
			field : 'color',
			title : '颜色',
			width : 80,
			align: 'center'
				
		},{
			field : 'size',
			title : '尺码',
			width : 80,
			align: 'center'
				
		}, {
			field : 'numPerHand',
			title : '齐码/单位',
			width : 75,
			align: 'center',
			formatter: function (value, row, index){
				return row.numPerHand + row.unit;
			}
		}, {
			field : 'factorySalesPrice',
			title : '厂家零售价',
			width : 75,
			align: 'center'
		}, 
		 {
			field : 'discount',
			title : '折扣',
			width : 60,
			align: 'center'
		},{
			field : 'salesPrice',
			title : '千禧零售价',
			width : 70,
			align: 'center'
		}, {
			field : 'cost',
			title : '进价',
			width : 60,
			align: 'center'
		}, {
			field : 'wholeSalePrice',
			title : '预设价1',
			width : 70,
			align: 'center'
		},	{			
			field : 'barcode',
			title : '货品条形码',
			width : 120,
			align: 'center'
		}, {
			field : 'createBy',
			title : '录入人员',
			width : 90,
			align: 'center'
		},{
			field : 'lastUpdateBy',
			title : '最后修改人',
			width : 90,
			align: 'center'
		},{
			field : 'createTime',
			title : '创建时间',
			width : 140
		}, {	
			field : 'action',
			title : '修改',
			width : 70,
			align: 'center',
			formatter : function(value, row, index) {

				var str = $.formatString('<a href="#" onclick="viewBarcodeDetails(\'{0}\');"><img border="0" src="{1}" title="修改"/></a>', row.barcode,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/text_1.png');
				
				return str;
			}
		}, {	
			field : 'copy',
			title : '复制',
			width : 70,
			align: 'center',
			formatter : function(value, row, index) {
				var copyInfo = row.year + " "  + row.quarter + " "  + row.brand + " "  + row.categoryLevel + " "  + row.category + " "  + row.productCode + " "  + row.color + " "  + row.size + " "  + row.numPerHand + "/"  + row.unit + " "  + row.factorySalesPrice + " "  + row.discount + " "  + row.salesPrice + " "  + row.cost + " "  + row.wholeSalePrice + " "  + row.barcode;

				var str = $.formatString('<a href="#" onclick="copy(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="修改"/></a>', copyInfo,row.barcode,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/redo.png');
				
				return str;
			}
		}
		]],
		toolbar : '#toolbar',
	});
	
});



/**
 * 根据条码查询/修改条码详情
 */
function viewBarcodeDetails(barcode){
	var url = 'productJSPAction!searchForUpdate?formBean.productBarcode.barcode=' + barcode;
	window.open (url,'新窗口','height=950, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}

/**
 * 根据条码查询/修改条码详情
 */
function copy(copyInfo,barcode){
	
	 const textarea = document.createElement('textarea');
	 textarea.value = copyInfo;	 
	  // 添加到文档中
	  textarea.style.position = 'fixed';
	  textarea.style.left = '0';
	  textarea.style.top = '0';
	  document.body.appendChild(textarea);
	 
	  // 选择文本
	  textarea.select();
	  
	  try {
	    const result = document.execCommand('copy');
	    if (result) {
	    	$.messager.show({
                title:'提示',
                msg: barcode +'复制成功',
                showType:'slide',
                timeout:'140',
                style:{                  
                    top:document.body.scrollTop+document.documentElement.scrollTop,
                    bottom:''
                }
            });
	    } else {
	    	$.messager.show({
	    		title:'提示',
	            msg: barcode +'复制失败',
                showType:'slide',
                timeout:'140',
                style:{
                    right:'',
                    top:document.body.scrollTop+document.documentElement.scrollTop,
                    bottom:''
                }
            });
	    }
	  } catch (error) {
		  $.messager.show({
			  title:'提示',
	          msg: barcode +'复制异常',
	          timeout:'140',
              showType:'slide',
              style:{
                  right:'',
                  top:document.body.scrollTop+document.documentElement.scrollTop,
                  bottom:''
              }
          });
	  }	 
	  // 移除元素
	  textarea.remove();
}


/**
 * to ensure user has select some criteria
 */
function validateSearch(){
	$("#brands").find("option").attr("selected","selected"); 
	var area = $("#area_ID").val();
	var year = $("#year_ID").val();
	var quarter = $("#quarter_ID").val();
	var brand = $("#brands").val();
	var category = $("#category_ID").val();
	var productCode = $("#productCode").val();
	var barcode = $("#barcode").val();
	var time = $("#needCreateDate").is(':checked');
	if (year==0 && quarter==0 && brand==null && category==0 && productCode == "" && barcode=="" && time==false){
		$.messager.alert('失败信息', "请在选项（年份，季度，品牌，货品，货号，条形码，录入时间）中选出你的条码范围，否则数据量太庞大!",'error');
		return false;
	} else
		return true;
}

function exportBarcodeToExcel(){
	if (validateCheckbox()){
		var url = "action/productJSPAction.action";
		document.searchedBarcodeForm.action = url;
		document.searchedBarcodeForm.submit();	
	}
}

function exportToPrintBarcode(){
	if (validateCheckbox()){
		var url = "action/productJSPAction!exportToPrintBarcode";
		document.searchedBarcodeForm.action = url;
		document.searchedBarcodeForm.submit();	
	}
}


function searchBarcode(){
	var categoryId = $("#category_ID").combo("getValue");
	if (categoryId != "0" && !isValidPositiveInteger(categoryId)){
		$.messager.alert('失败信息', "货品类别不是一个正确的输入",'error');
		return;
	}

    if (validateSearch()){
    	var params = $.serializeObject($('#barcodeSearchForm'));
		$('#dataGrid').datagrid('load',params); 
    }
}



function clearAllData(){
	$("#error").html("");
	$("#tip").html("");

    $('#orgTablebody tr').each(function () {                
        $(this).remove();
    });
}
function showCreateDate(){
	if ($("#needCreateDate").attr("checked") == 'checked')
		$("#createDateDiv").show();
	else
		$("#createDateDiv").hide();
}
function selectAll(){

	if ($("#selectAllCheck").prop("checked") == true)
		$("input[name='selectedBarcodes']").prop("checked",true); 
	else
		$("input[name='selectedBarcodes']").prop("checked",false); 
	
}
function validateCheckbox(){
	if ($("input[name='selectedBarcodes']:checked").length == 0){
		$.messager.alert('失败信息', "请先选中货品",'error');
		return false;
	}
	return true;
}
function removeBrand(){
	$("#brands").find("option:selected").each(function(){
	   var removeColor = $(this).val();
	   if (removeColor != 0 && removeColor != undefined)
		   $("#brands option[value='"+removeColor+"']").remove();  
       });
}
/**
 * once click the button, it will help to search brand
 */
function searchBrand(){
	var brandName = $.trim($("#brandName").val());
	if (brandName != "") {
	    var params= "formBean.productBarcode.product.brand.brand_Name=" + brandName  ; 
    
        var url = encodeURI(encodeURI("productJSPAction!scanBrand?" +params));
	
        window.open(url,'_blank','height=400, width=300, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');  
	} else {
        $.messager.alert('失败信息', "请输入品牌名称",'error');
    } 
}

/**
 * user click the brand
 */
function selectBrand(brandName, brandId){
	if (brandName != "" && brandId != "" && brandId != 0){
		 $("#brandName").textbox("setValue",brandName)
    }
    
	var added = false;
     $("#brands option").each(function(){
     	   if($(this).val() == brandId)
     	      added = true;
     	   });
    if (added == false)
       $("#brands").append("<option value='"+ brandId+"'>"+ brandName+"</option>");
}
</script>


</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',border:false" style="height: 210px;">
			<s:form id="barcodeSearchForm" action="" method="POST" theme="simple">
				<input type="hidden" id="isInitialized"
					name="formBean.isInitialized" />
				<table width="100%" border="0">
				
					<tr class="InnerTableContent">
						<td width="40"></td>
						<td  colspan="3"><strong>请选择查询条件：</strong></td>
					</tr>
					<tr class="InnerTableContent">
							<td height="4" colspan="13"><hr width="100%" color="#FFCC00" /></td>
					</tr>
					<tr class="InnerTableContent">
						<td></td>
						<td width="65" align="center" height="19"><strong>年份：</strong></td>
						<td width="175"><s:select  cssClass="easyui-combobox" style="width:130px;text-align: center"
								name="formBean.productBarcode.product.year.year_ID" size="1"
								id="year_ID" list="uiBean.basicData.yearList" listKey="year_ID"
								listValue="year" headerKey="0" headerValue="-----全选-----" /></td>
						<td width="60" align="center"><strong>季度：</strong></td>
						
						<td width="175" ><s:select  cssClass="easyui-combobox" style="width:130px;text-align: center"
								name="formBean.productBarcode.product.quarter.quarter_ID"
								size="1" id="quarter_ID" list="uiBean.basicData.quarterList"
								listKey="quarter_ID" listValue="quarter_Name" headerKey="0"
								headerValue="-----全选-----" /></td>
								
								
						<td width="65" align="center"><strong>产品线：</strong></td>
						<td width="175"><s:select  style="width:130px;"
 								name="formBean.productBarcode.product.categoryLevel1.category_ID"
								size="1" cssClass="easyui-combobox" id="category_level_ID"
								data-options="prompt:'请选择产品线'"
								list="uiBean.basicData.categoryLevelList" listKey="category_ID"
								listValue="category_Name" headerKey="0" headerValue="" /></td>

						
						<td width="65" align="center"><strong>货品类：</strong></td>
						<td width="155"><s:select
								name="formBean.productBarcode.product.category.category_ID"
								size="1" cssClass="easyui-combobox" id="category_ID"
								data-options="prompt:'请选择货品类'"
								list="uiBean.basicData.categoryList" listKey="category_ID"
								listValue="category_Name" headerKey="0" headerValue="" /></td>
						<td width="60" align="center"><strong>最小码：</strong></td>
						<td width="155"><input type="text" style="width:120px;" class="easyui-numberbox"  
								data-options="prompt:'请输入产品最小码'"
								name="formBean.productBarcode.product.sizeMin"
								id="sizeMin" /></td>
																		
						<td width="60" align="center"><strong>最大码：</strong></td>
						<td><input type="text"  style="width:120px;"  class="easyui-numberbox"  
								data-options="prompt:'请输入产品最大码'"
								name="formBean.productBarcode.product.sizeMax" 
								id="sizeMax"/></td>
			
					</tr>
					<tr class="InnerTableContent">
							<td height="2" colspan="13"><hr width="100%" color="#FFCC00" /></td>
					</tr>
					<tr class="InnerTableContent">
						<td></td>
						<td width="60" align="center" height="19"><strong>货号：</strong></td>
						<td><input type="text"  style="width:135px;"  class="easyui-textbox"
							data-options="prompt:'请输入产品货号'"
							name="formBean.productBarcode.product.productCode"
							id="productCode"  /></td>
						<td height="19" align="center"><strong>条形码：</strong></td>
						<td><input type="text"  style="width:135px;" name="formBean.productBarcode.barcode" class="easyui-textbox"
							data-options="prompt:'请输入12位的条码'"
							id="barcode"  /></td>
						<td align="center"><strong>品牌：</strong></td>								
						<td ><s:textfield cssClass="easyui-searchbox" style="width:135px;" data-options="prompt:'请输入品牌名',searcher:searchBrand"
								name="formBean.productBarcode.product.brand.brand_Name"  
								id="brandName" /> </td>
						<td ><strong>已选品牌：</strong></td>	
						<td colspan="2" ><select
							name="formBean.brandIds" id="brands" multiple size="3"
							style="width: 180px"></select>
							
							</td>
						<td><a href="#" id="removeBt" class="easyui-linkbutton" data-options="iconCls:'icon-cut',toggle:true" onclick="removeBrand();">清除</a></td>
						
						

					</tr>
					<tr class="InnerTableContent">
							<td height="4" colspan="13"><hr width="100%" color="#FFCC00" /></td>
					</tr>
					<tr>
					<td></td>
					<td height="19" align="center"><strong>录入时间：</strong></td>
					<td height="19" colspan="4">
							<table border="0">
								<tr>
									<td><input type="checkbox" name="formBean.needCreateDate"
										id="needCreateDate" onClick="showCreateDate();" value="true"
										checked /></td>
									<td>
										<div id="createDateDiv" style="display: block">
											开始日期 ：
											<s:textfield id="startDate" name="formBean.startDate"
												cssClass="easyui-datebox"
												data-options="width:100,editable:false" />
											&nbsp;&nbsp;&nbsp; 截止日期 ：
											<s:textfield id="endDate" name="formBean.endDate"
												cssClass="easyui-datebox"
												data-options="width:100,editable:false" />
										</div>
									</td>
								</tr>
							</table>
						</td>
						<td colspan="2" >仅总部<input type="radio"
							name="formBean.productBarcode.chainStore.chain_id" value="99"
							checked /> 仅连锁店<input type="radio"
							name="formBean.productBarcode.chainStore.chain_id" value="0" />
							所有<input type="radio"
							name="formBean.productBarcode.chainStore.chain_id" value="-1" />
						</td>
					</tr>
					<tr class="InnerTableContent">
							<td height="4" colspan="13"><hr width="100%" color="#FFCC00" /></td>
					</tr>
				</table>
			</s:form>
		</div>
				<div data-options="region:'center',border:false">
			<table id="dataGrid" border="0">
			</table>
			<form name="searchedBarcodeForm" id="searchedBarcodeForm" action=""
	method="post"></form>
			<tbody id="orgTablebody">
		</tbody>
			
			<div id="toolbar" style="display: none; height:30px;" >
				
				<a onclick="searchBarcode();" href="javascript:void(0);"
					class="easyui-linkbutton" style="height:25px;"
					data-options="iconCls:'icon-search'">查询条码</a>
										

			</div>
		</div>

	</div>
	<br />
</body>
</html>